﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="edit_crossword.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Game.edit_crossword" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        int id = int.Parse(Request.QueryString["id"]);
        var get_crossword = new TblCrossWordQuestionController().FetchAll().Single(x => x.Id == id);
    %>
    <header class="w3-center w3-padding-4">
        <label>Sửa câu hỏi</label>
    </header>
    <div class="w3-row w3-padding">
        <label class="w3-col l2">Tên câu hỏi</label><input id="edit_crossword_name" value="<%=get_crossword.Name %>" type="text" class="game-text w3-light-grey w3-col l10" />
    </div>
    <div class="w3-row w3-padding">
        <div class="w3-col w3-col l5 w3-row">
            <label class="w3-quarter">Số hàng</label><input type="number" value="<%=get_crossword.VerticalTotal %>" min="1" max="25" id="edit-game-apb-table-row-number" class="game-text w3-light-grey w3-col l8" />
        </div>
        <div class="w3-col w3-col l5 w3-row">
            <label class="w3-quarter">Số cột</label><input type="number" min="1" max="25" value="<%=get_crossword.HorizontalTotal %>" id="edit-game-apb-table-col-number" class="game-text w3-light-grey w3-col l8" />
        </div>
        <div class="w3-col l2">
            <a class="game-create-alphabets-table-btn w3-btn w3-teal w3-right">Tạo ô chữ</a>
        </div>
        <div id="game_edit_primary_hor" class="w3-hide"><%=get_crossword.PrimaryHorizontal %></div>
    </div>
    <div id="edit-game-apb-table-add-vertical" class="game-apb-table-add-vertical w3-row w3-padding">
        <label class="w3-col l2">Câu hỏi chính</label><textarea id="edit_primary_question_crossword" placeholder="Nhập câu hỏi hàng dọc" class="game-edit-vertical-area game-text w3-light-grey w3-col l8"><%=get_crossword.PrimaryQuestion %></textarea><a onclick="edit_game_done_vertical()" class="game-apb-table-done-vertical-btn w3-col l2 w3-btn w3-teal">Xong</a>
    </div>
    <div class="w3-padding">
        <div id="edit-game-apb-table-box" class="w3-center w3-padding w3-border w3-border-light-grey">
            <%if (get_crossword.VerticalTotal > 0 && get_crossword.HorizontalTotal > 0)
                { %>
            <table id="edit-game-new-apb-table" class="game-new-apb-table" style="display: inline-block;">
                <tbody>
                    <tr class="first-row row-1">
                        <td></td>
                        <%for (int j = 0; j < get_crossword.HorizontalTotal; j++)
                            {
                                if (j != get_crossword.PrimaryHorizontal - 1)
                                {
                        %>
                        <td class="col<%=j %>">
                            <a onclick="edit_game_choose_vertical(this.parentElement.className,<%=j %>)" title="Chọn từ khoá hàng dọc" class="game-apb-table-option-btn game-apb-table-choose-vertical-btn w3-btn w3-light-grey w3-text-teal" style="display:none"><i class="fa fa-chevron-down"></i></a>
                            <a onclick="edit_game_cancel_vertical()" title="Chọn lại từ khoá hàng dọc" class="game-apb-table-option-btn game-apb-table-cancel-vetical-btn w3-btn w3-deep-orange"><i class="fa fa-chevron-up"></i></a>
                        </td>
                        <%}else { %>
                        <td class="col<%=j %>">
                            <a onclick="edit_game_choose_vertical(this.parentElement.className,<%=j %>)" title="Chọn từ khoá hàng dọc" class="game-apb-table-option-btn game-apb-table-choose-vertical-btn w3-btn w3-light-grey w3-text-teal" style="display:none"><i class="fa fa-chevron-down"></i></a>
                            <a onclick="edit_game_cancel_vertical()" title="Chọn lại từ khoá hàng dọc" class="game-apb-table-option-btn game-apb-table-cancel-vetical-btn w3-btn w3-deep-orange" style="display:inline-block"><i class="fa fa-chevron-up"></i></a>
                        </td>
                        <%} %>
                        <%} %>
                        <td></td>
                    </tr>
                    <%
                        var get_question = new TblCrossWordDetailsQuestionController().FetchAll().Where(x => x.CrossWordId == get_crossword.Id).ToList();
                        for (int i = 0; i < get_question.Count; i++)
                        {
                            var get_word = (from p in new TblCrossWordDetailsWordController().FetchAll().Where(x => x.Vertical == get_question[i].Vertical && x.CrosswordId == get_question[i].CrossWordId) orderby p.Horizontal ascending select p).ToList();
                    %>
                    <tr id="edit_row<%=get_question[i].Id %>" class="another-row row<%=get_question[i].Id %> done">
                        <td>
                            <%--<a onclick="game_edit_horizol(this.parentElement.parentElement.id)" title="Thêm câu hỏi hàng ngang" class="game-apb-table-add-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal"><i class="fa fa-plus"></i></a>--%>
                            <a onclick="edit_game_edit_horizol(this.parentElement.parentElement.id)" title="Chỉnh sửa câu hỏi hàng ngang" class="game-apb-table-edit-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal" style="display:inline-block"><i class="fa fa-cog"></i></a>
                            <div class="edit-game-apb-table-horizol-question-box w3-hide"><%=get_question[i].Question %></div>
                        </td>
                        <%for (int j = 0; j < get_word.Count; j++)
                            { %>
                        <td class="col<%=j %>">
                            <input type="text" maxlength="1" placeholder="?" <%if(j==get_crossword.PrimaryHorizontal-1) { %>class="w3-deep-orange choose choosen"<%} %> value="<%=get_word[j].Word %>" disabled="disabled" /></td>
                        <%} %>
                        <td><a onclick="edit_game_delete_horizol(this.parentElement.parentElement.id)" title="Xoá hàng ngang này" class="game-apb-table-delete-horizol-btn game-apb-table-option-btn w3-btn w3-light-grey w3-text-teal"><i class="fa fa-times"></i></a></td>
                    </tr>
                    <%} %>
                    <tr class="last-row row3">
                        <td></td>
                        <%for (int j = 0; j < get_crossword.HorizontalTotal; j++)
                            {%>
                        <td class="col<%=j %>"><a onclick="edit_game_delete_vertical(this.parentElement.className)" title="Xoá hàng dọc này" class="game-apb-table-option-btn game-apb-table-delete-vertical-btn w3-btn w3-light-grey w3-text-teal"><i class="fa fa-times"></i></a></td>
                        <%} %>
                        <td></td>
                    </tr>
                </tbody>
            </table>
            <%}
                else
                { %>

            <div id="edit-game-apb-table-tutorial" class="w3-padding-64 w3-light-grey">
                <p class="w3-large w3-text-grey">Nhập vào số hàng và số cột lớn hơn 0 để tạo ô chữ</p>
                <i class="w3-xxlarge fa fa-table w3-text-grey"></i>
            </div>
            <%} %>
        </div>
    </div>
    <div id="game-apb-table-edit-horizol" class="game-apb-table-edit-horizol w3-row w3-padding" style="display:none">
        <label class="w3-col l2">Câu hỏi hàng ngang</label><textarea placeholder="Nhập câu hỏi hàng ngang" class="game-edit-horizol-area game-text w3-light-grey w3-col l6"></textarea><a onclick="game_done_edit_horizol()" class="game-apb-table-done-vertical-btn w3-btn w3-teal w3-col l2">Xong</a><a onclick="game_cancel_edit_horizol()" class="game-apb-table-cancel-horizol-btn w3-btn w3-deep-orange w3-col l2">Huỷ</a>
    </div>
    <div class="w3-padding w3-center">
        <a onclick="btn_edit_crossword(<%=get_crossword.Id %>)" class="w3-btn w3-teal"><i class="fa fa-check"></i>&nbsp;Xác nhận</a>
        <a onclick="game_delete_question(<%=id %>)" class="w3-btn w3-deep-orange"><i class="fa fa-trash"></i>&nbsp;Xoá câu hỏi</a>
    </div>
</body>
</html>
